<?php

namespace App\Store\Models\Wxapp;

use App\Common\Services\Common;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use App\Common\Services\Store\Common as StoreCommon;

class Electronicchop extends Model
{
    protected $table = 'site_wxapp_electronicchop';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];
    public static function getList(Request $request)
    {
        $cp_id = StoreCommon::getCurrentAccountCompanyId($request);
        $query = self::where('cp_id', $cp_id)->orderBy('create_at', 'desc');
        $isgetall = intval($request->isgetall) ?? 0;
        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return Common::paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
    public static function getListByMem(Request $request, $cp_id)
    {
        $query = self::where('is_del', 1)->where('cp_id', $cp_id)->orderBy('create_at', 'desc');
        $isgetall = intval($request->isgetall) ?? 0;
        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return Common::paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
}
